Jpeg, Png Image to Webp converter

A Jpeg, Png Image to Webp converter is a software tool or program that allows users to convert images in Jpeg or Png format to the Webp format. Webp is an image file format developed by Google that provides superior image compression without compromising image quality. This converter helps optimize image sizes for web usage, reducing file sizes and improving website loading times.

- Follow the instructions below -

Step 1:  For a quick and easy way to get started converting your images, Download libwebp-1.3.2-windows-x64.zip : 64-bit executables and libraries for Windows-x64 platform.

Step 2:  Extract the downloaded Zip file to any place in your system.

Step 3:  Copy the code snippet to notepad and save it in .ps1 format.

Step 4:  Change the path of the file in the code where it says "C:\Users\Administrator\Downloads\libwebp-1.3.0-windows-x64\libwebp-1.3.0-windows-x64\bin\cwebp.exe". Point the path of the file to which you have downloaded. Make sure you are pointing the path to the right file [libwebp-1.3.0-windows-x64 -> bin -> cwebp.exe].

Step 5:  Then right click on the file and select "Run with powershell" to run the program.

Step 6:  Select base folder where your png and jpeg images are located. Then select the output folder where you want to keep the converted images. webpConverter image

Step 7:  Click on Convert Image to WebP button to start the conversion.

Step 8:  Check your output folder for the converted files.

                                        
# Jpeg, Png Image to Webp converter
Add-Type -AssemblyName PresentationFramework, System.Windows.Forms

# Create the WPF window
$window = New-Object -TypeName System.Windows.Window
$window.Title = "WebP Converter"
$window.Width = 700
$window.Height = 400
$window.ResizeMode = "NoResize"
$window.WindowStartupLocation = "CenterScreen"
$window.FontSize = 12

# Create a label for "Select base Folder"
$labelBaseFolder = New-Object -TypeName System.Windows.Controls.Label
$labelBaseFolder.Content = "Select base Folder:"
$labelBaseFolder.Margin = "10,20,0,0"
$labelBaseFolder.HorizontalAlignment = "Left"

# Create a textbox for base folder path
$textBaseFolder = New-Object -TypeName System.Windows.Controls.TextBox
$textBaseFolder.Width = 350
$textBaseFolder.Margin = "5,25,0,305"

# Create a button for browsing base folder
$buttonBaseFolder = New-Object -TypeName System.Windows.Controls.Button
$buttonBaseFolder.Width = 80
$buttonBaseFolder.Content = "Browse"
$buttonBaseFolder.Margin = "550,25,0,305"
$buttonBaseFolder.HorizontalAlignment = "Left"
$buttonBaseFolder.Add_Click({
    $dialog = New-Object -TypeName System.Windows.Forms.FolderBrowserDialog
    $dialog.Description = "Select base Folder"
    if ($dialog.ShowDialog() -eq "OK") {
        $textBaseFolder.Text = $dialog.SelectedPath
    }
})

# Create a label for "Select Output Folder"
$labelOutputFolder = New-Object -TypeName System.Windows.Controls.Label
$labelOutputFolder.Content = "Select Output Folder:"
$labelOutputFolder.Margin = "10,90,0,0"
$labelOutputFolder.HorizontalAlignment = "Left"

# Create a textbox for output folder path
$textOutputFolder = New-Object -TypeName System.Windows.Controls.TextBox
$textOutputFolder.Width = 350
$textOutputFolder.Margin = "5,90,0,240"

# Create a button for browsing output folder
$buttonOutputFolder = New-Object -TypeName System.Windows.Controls.Button
$buttonOutputFolder.Width = 80
$buttonOutputFolder.Content = "Browse"
$buttonOutputFolder.Margin = "550,90,0,240"
$buttonOutputFolder.HorizontalAlignment = "Left"
$buttonOutputFolder.Add_Click({
    $dialog = New-Object -TypeName System.Windows.Forms.FolderBrowserDialog
    $dialog.Description = "Select Output Folder"
    if ($dialog.ShowDialog() -eq "OK") {
        $textOutputFolder.Text = $dialog.SelectedPath
    }
})

# Create a button for converting images to WebP
$buttonConvert = New-Object -TypeName System.Windows.Controls.Button
$buttonConvert.Width = 150
$buttonConvert.Height = 30
$buttonConvert.Content = "Convert Image to WebP"
$buttonConvert.Margin = "10,70,0,100"
$buttonConvert.HorizontalAlignment = "Center"
$buttonConvert.Add_Click({
    $baseFolder = $textBaseFolder.Text
    $outputFolder = $textOutputFolder.Text

    if (-not (Test-Path -Path $baseFolder)) {
        [System.Windows.MessageBox]::Show("Base folder does not exist.", "Error", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
        return
    }

    if (-not (Test-Path -Path $outputFolder)) {
        [System.Windows.MessageBox]::Show("Output folder does not exist.", "Error", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Error)
        return
    }

    $images = Get-ChildItem -Path $baseFolder -File

    $successCount = 0
    $failureCount = 0

    foreach ($img in $images) {
        $outputName = Join-Path -Path $outputFolder -ChildPath ($img.BaseName + ".webp")

        # Perform the conversion here
        # ...
        C:\Users\Administrator\Downloads\libwebp-1.3.0-windows-x64\libwebp-1.3.0-windows-x64\bin\cwebp.exe $img.FullName -q 85 -o $outputName
        
        if ($true) {  # Replace with your conversion logic
            $successCount++
        }
        else {
            $failureCount++
        }
    }

    $message = "Conversion Success for $successCount Images`nConversion failed for $failureCount Images"
    $caption = "Conversion Result"
    $icon = if ($failureCount -gt 0) { [System.Windows.MessageBoxImage]::Error } else { [System.Windows.MessageBoxImage]::Information }
    [System.Windows.MessageBox]::Show($message, $caption, [System.Windows.MessageBoxButton]::OK, $icon)
})

# Create a label for conversion result
$labelResult = New-Object -TypeName System.Windows.Controls.Label
$labelResult.Width = 300
$labelResult.Height = 40
$labelResult.Margin = "5,130,0,0"
$labelResult.HorizontalAlignment = "Center"

# Create a copyright label
$labelCopyright = New-Object -TypeName System.Windows.Controls.Label
$labelCopyright.Content = "TrekTraveller - 2023"
$labelCopyright.Margin = "540,330,0,0"

# Add the elements to the window
$window.Content = New-Object -TypeName System.Windows.Controls.Grid
$window.Content.Children.Add($labelBaseFolder)
$window.Content.Children.Add($textBaseFolder)
$window.Content.Children.Add($buttonBaseFolder)
$window.Content.Children.Add($labelOutputFolder)
$window.Content.Children.Add($textOutputFolder)
$window.Content.Children.Add($buttonOutputFolder)
$window.Content.Children.Add($buttonConvert)
$window.Content.Children.Add($labelResult)
$window.Content.Children.Add($labelCopyright)

# Show the window
$window.ShowDialog()
                                    
                                    


Leave a comment


Loading